package com.woniuxy.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.dto.GoodsAppraisalHistoryDto;
import com.woniuxy.dto.commonDto.BaseDto;
import com.woniuxy.entity.GoodsAppraisalHistory;
import com.woniuxy.enums.CodeEnum;
import com.woniuxy.exception.AppraisalException;
import com.woniuxy.mapper.GoodsAppraisalHistoryMapper;
import com.woniuxy.param.BaseParam;
import com.woniuxy.param.GoodsAppraisalHistoryParam;
import com.woniuxy.param.GoodsAppraisalParam;
import com.woniuxy.service.GoodsAppraisalHistoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.util.PageMysqlUtil;
import com.woniuxy.util.WoniuBeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 评估鉴定里面的历史鉴定记录 服务实现类
 * </p>
 *
 * @author zcx,ftl,gr,rhs
 * @since 2021-12-31
 */
@Service
public class GoodsAppraisalHistoryServiceImpl extends ServiceImpl<GoodsAppraisalHistoryMapper, GoodsAppraisalHistory> implements GoodsAppraisalHistoryService {

    //分页查询鉴定记录
    @Override
    public BaseDto<GoodsAppraisalHistoryDto> getAppraisalHistory(GoodsAppraisalHistoryParam gah) {
        QueryWrapper qw = new QueryWrapper();

        BaseDto<GoodsAppraisalHistoryDto> baseDto = PageMysqlUtil.pageQuery
                (GoodsAppraisalHistoryDto.class, this, qw, new BaseParam(gah.getIndexPage(), gah.getPageSize()));

        return baseDto;
    }

    //添加鉴定记录
    @Override
    public boolean addGoodsAppraisal(GoodsAppraisalParam gap) {
//        GoodsAppraisalHistory commodity_table_id = getOne(new QueryWrapper<GoodsAppraisalHistory>().eq("commodity_table_id", gap.getCommodityTableId()));
//
//        if (!StringUtils.isEmpty(commodity_table_id)) {
//            throw new AppraisalException(CodeEnum.APPRAISAL_SAVE_FAIL_1.getMessage()
//                    , CodeEnum.APPRAISAL_SAVE_FAIL_1.getCode());
//        }
        GoodsAppraisalHistory goodsAppraisalHistory = WoniuBeanUtils.copyObject(gap, GoodsAppraisalHistory.class);
//        System.out.println(goodsAppraisalHistory);
        return save(goodsAppraisalHistory);

    }
}
